import { View } from "../../../../../mvc/core/View";
import { LayerManager } from "../../../../manager/LayerManager";
import { GlobalClass } from "../../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../../resource/ImagesConst";
import { ObjCreate } from "../../../common/ObjCreate";
import { Language } from "../../../../../../extend/language/Language";
import { GTextFormat } from "../../../../../common/GTextFormat";
import { FontUtil } from "../../../../../common/font/FontUtil";
import { GSprite } from "../../../../../../com/mui/controls/GSprite";
import { GuildEliteGroupPanelGroup } from "./GuildEliteGroupPanelGroup";
import { GModuleEvent } from "../../../../mvc/GModuleEvent";
import { DataEvent } from "../../../../events/DataEvent";
import { Dispatcher } from "../../../../../mvc/core/Dispatcher";
import { EventName } from "../../../../mvc/EventName";
import { SceneRange } from "../../../../scene/map/SceneRange";
import { Global } from "../../../../../../com/gengine/global/Global";
import { GTextFiled } from "../../../../../../com/mui/controls/GTextFiled";
import { GButton } from "../../../../../../com/mui/controls/GButton";
type int = number;
//class GuildEliteGroupPanel
    
    export  class GuildEliteGroupPanel extends View
    {
        constructor()
        {
            super();
            this._moveRec = new Object /* flash.geom.Rectangle */();
            this.layer = LayerManager.uiLayer;
            this.mouseEnabled = false;
            this.createChildren();
            return;
        }

        protected createChildren(): void
        {
            this._titleSp = new Object /* flash.display.Sprite */();
            this._titleSp.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onMoveBtnMouseDown);
            this.addChild(this._titleSp);
            var loc1=GlobalClass.getScaleBitmap(ImagesConst.ButtonBig_upSkin, new Object /* flash.geom.Rectangle */(40, 10, 40, 6));
            loc1.width = 260;
            loc1.height = 32;
            this._titleSp.addChild(loc1);
            this._titleText = ObjCreate.createGTextField(Language.getString(60650), 0, 6, 260, 20, this._titleSp, new GTextFormat(FontUtil.stXingkaiName, 16, 16776960, null, null, null, null, null, flash.text.TextFormatAlign.CENTER), true, false);
            this._zoomBtn = ObjCreate.createGButton("", 5, 4, 24, 22, this._titleSp, "SubBtn2");
            this._zoomBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onZoomBtnClickHandler);
            this._zoomBtn.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onMoveBtnMouseDown);
            this._groupBtn = ObjCreate.createGButton(Language.getString(60683), 209, 5, 40, 20, this._titleSp);
            this._groupBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onGroupBtnClickHandler);
            this._groupBtn.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onMoveBtnMouseDown);
            this._bodySp = new GSprite();
            this._bodySp.x = 1;
            this._bodySp.y = 29;
            this._bodySp.mouseEnabled = false;
            this.addChild(this._bodySp);
            this._bg = new Object /* flash.display.Bitmap */(new Object /* flash.display.BitmapData */(257, 200, false, 0));
            this._bg.alpha = 0.45;
            this._bodySp.addChild(this._bg);
            this._group1 = this.createGroup(1, 2, 3);
            this._group2 = this.createGroup(2, 130, 3);
            this._group3 = this.createGroup(3, 2, 132);
            this._group4 = this.createGroup(3, 130, 132);
            this.updateSize();
            return;
        }

        /* internal  */createGroup(arg1: int, arg2: int, arg3: int): GuildEliteGroupPanelGroup
        {
            var loc1;
            (loc1 = new GuildEliteGroupPanelGroup(arg1)).x = arg2;
            loc1.y = arg3;
            loc1.addEventListener(GModuleEvent.GuildGroup_GroupPanelSizeChange, this.onGroupPanelSizeChangeHandler);
            this._bodySp.addChild(loc1);
            return loc1;
        }

        /* internal  */onGroupPanelSizeChangeHandler(arg1: DataEvent): void
        {
            this.updateSize();
            return;
        }

        /* internal  */onZoomBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._isSmall = !this._isSmall;
            if (this._isSmall) 
            {
                this._zoomBtn.styleName = "SupBtn2";
            }
            else 
            {
                this._zoomBtn.styleName = "SubBtn2";
            }
            this._zoomBtn.drawNow();
            this.updateSize();
            return;
        }

        /* internal  */onGroupBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildEliteGroup_ShowGroupModule, null));
            return;
        }

        /* internal  */updateSize(): void
        {
            if (this._isSmall) 
            {
                if (this._bodySp.parent) 
                {
                    this._bodySp.parent.removeChild(this._bodySp);
                }
            }
            else 
            {
                this.addChild(this._bodySp);
                this._group3.y = this._group1.y + this._group1.height + 3;
                this._group4.y = this._group2.y + this._group2.height + 3;
                this._bg.height = this.getTotalHeight();
            }
            return;
        }

        /* internal  */getTotalHeight(): int
        {
            var loc1=this._group1.height + this._group3.height;
            var loc2=this._group2.height + this._group4.height;
            return Math.max(loc1, loc2) + 10;
        }

        public updatePlayers(arg1: Map<any, any> /* flash.utils.Dictionary */): void
        {
            if (arg1 == null) 
            {
                this._group1.updateDataProvider(null);
                this._group2.updateDataProvider(null);
                this._group3.updateDataProvider(null);
                this._group4.updateDataProvider(null);
                return;
            }
            this._group1.updateDataProvider(arg1[1]);
            this._group2.updateDataProvider(arg1[2]);
            this._group3.updateDataProvider(arg1[3]);
            this._group4.updateDataProvider(arg1[4]);
            return;
        }

        /* internal  */onMoveBtnMouseDown(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._moveRec.x = 0;
            this._moveRec.y = 0;
            this._moveRec.width = SceneRange.display.width - 30;
            this._moveRec.height = SceneRange.display.height - 30;
            startDrag(false, this._moveRec);
            Global.stage.addEventListener(flash.events.MouseEvent.MOUSE_UP, this.onStageMouseUpHandler);
            return;
        }

        /* internal  */onStageMouseUpHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            stopDrag();
            Global.stage.removeEventListener(flash.events.MouseEvent.MOUSE_UP, this.onStageMouseUpHandler);
            return;
        }

        /* internal */ /* var */_isSmall: Boolean=false;

        /* internal */ /* var */_titleSp: Object /* flash.display.Sprite */;

        /* internal */ /* var */_titleText: GTextFiled;

        /* internal */ /* var */_zoomBtn: GButton;

        /* internal */ /* var */_groupBtn: GButton;

        /* internal */ /* var */_bodySp: GSprite;

        /* internal */ /* var */_bg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_group1: GuildEliteGroupPanelGroup;

        /* internal */ /* var */_group2: GuildEliteGroupPanelGroup;

        /* internal */ /* var */_group3: GuildEliteGroupPanelGroup;

        /* internal */ /* var */_group4: GuildEliteGroupPanelGroup;

        /* internal */ /* var */_moveRec: Object /* flash.geom.Rectangle */;
    }
